package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@AllArgsConstructor
public class NursingProjectServiceImpl implements NursingProjectService {

    private final NursingProjectMapper nursingProjectMapper;

    /**
     * 根据条件分页查询护理项目
     *
     * @param name
     * @param status
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public ResponseResult getByPage(String name, Integer status, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<NursingProjectVo> nursingProjects = nursingProjectMapper.selectByPage(name, status);
        Page<NursingProjectVo> pages = (Page<NursingProjectVo>) nursingProjects;
        return ResponseResult.success(PageResponse.of(pages, NursingProjectVo.class));
    }


    /**
     * 新增护理项目
     * @param nursingProjectDTO
     * @return
     */
    @Override
    public void add(NursingProjectDto nursingProjectDTO) {
        NursingProject nursingProject = BeanUtil.copyProperties(nursingProjectDTO, NursingProject.class);
        nursingProjectMapper.add(nursingProject);
    }


    /**
     * 根据编号查询护理项目信息
     * @param id
     * @return
     */
    @Override
    public NursingProjectVo selectById(Long id) {
        NursingProject nursingProject = nursingProjectMapper.selectById(id);
        return BeanUtil.copyProperties(nursingProject, NursingProjectVo.class);
    }


    /**
     * 更新护理项目信息
     * @param nursingProjectDTO
     */
    @Override
    public void update(NursingProjectDto nursingProjectDTO) {
        NursingProject nursingProject = new NursingProject();
        BeanUtils.copyProperties(nursingProjectDTO, nursingProject);
        nursingProjectMapper.update(nursingProject);
    }

    /**
     * 启用和禁用护理项目
     * @param id
     * @param status
     */
    @Override
    public void enableOrDisable(Long id, Integer status) {
        nursingProjectMapper.updateStatus(id, status);
    }


    /**
     * 删除护理项目信息
     * @param id
     */
    @Override
    public void deleteById(Long id) {
        nursingProjectMapper.deleteById(id);
    }

}
